package symbolTable;

import java.util.ArrayList;
import syntaxtree.*;

public class StoreMethod {
	public String name;
	public Type returnType;
	public ArrayList<StoreVariable> parameters = new ArrayList<StoreVariable>();
	public ArrayList<StoreVariable> locals = new ArrayList<StoreVariable>();
	
	public void addParameter(String name, Type type){
		StoreVariable att = new StoreVariable();
		att.name = name;
		att.type = type;
		parameters.add(att);
	}
	
	public void addLocal(String name, Type type){
		StoreVariable att = new StoreVariable();
		att.name = name;
		att.type = type;
		locals.add(att);
	}
	
	public StoreVariable findFormal(String name){
		for(int i=0; i<parameters.size(); i++) //encontra a posicao
			if(parameters.get(i).name == name)
				return parameters.get(i);
		return null; //se nao achou
	}
	
	public StoreVariable findFormalByPos(int pos){
		if(pos >= parameters.size()) //se nao achou
			return null;
		return parameters.get(pos);
	}
	
	public StoreVariable findLocal(String name){
		for(int i=0; i<locals.size(); i++) //encontra a posicao
			if(locals.get(i).name == name)
				return locals.get(i);
		return null; //se nao achou
		
	}
}
